package cn.securityformail.rabbitmq.hello;

import cn.securityformail.rabbitmq.util.RabbitMQUtil;
import com.rabbitmq.client.*;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

@SuppressWarnings("all")
public class Customer {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitMQUtil.getConnection();
        //获得连接通道
        Channel channel = connection.createChannel();

        /**
         * 通道绑定消息队列
         *  1:队列名称,如果队列不存在则自动创建
         *  2:是否持久化队列 true 持久 false 不持久
         *  3:是否独占队列 true 独占 false 不独占
         *  4:是否在消费完成之后自动删除队列 true 删除 false不删除
         */
        channel.queueDeclare("hello",false,false,false,null);

        channel.basicConsume("hello",true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("new String():"+new String(body));
            }
        });

    }

}
